package com.xiaoma.pattern.proxy.jdk1;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * https://blog.csdn.net/weixin_43062845/article/details/100066042
 * <p>Title: InterceptorTest </p>
 * <p>Description：描述 </p>
 * <p>Package:com.xiaoma.pattern.proxy.jdk1 </p>
 * Date: 2022/5/26 12:25
 *
 * @author maj
 * @version 1.0.0
 */
public class InterceptorTest {

    /**
     * 实例动态代理工厂
     */
    IDynamicProxyFactory dynamicProxyFactory = new IDynamicProxyFactoryImpl();

    /**
     * 实例拦截器行为定义
     */
    ICustomInterceptor iCustomInterceptor = new ICustomInterceptorImpl();

    /**
     * 实例化业务登录
     */
    ILoginService iLoginService = new ILoginServiceImpl();

    @Test
    public void loginTest() {
        Map<String,Object> userInfo = new HashMap<>(1);
        userInfo.put("username","Tony");
        userInfo.put("password","123456");

        ILoginService proxy = dynamicProxyFactory.createProxy(iLoginService, iCustomInterceptor);
        Map<String, Object> loginResult = proxy.login(userInfo);
        System.out.println(loginResult);
    }

}
